package com.example.android_wx.activity;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AppCompatEditText;
import androidx.appcompat.widget.AppCompatImageView;
import androidx.appcompat.widget.AppCompatRadioButton;
import androidx.appcompat.widget.AppCompatTextView;

import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.example.android_wx.R;
import com.example.android_wx.base.App;
import com.example.android_wx.base.BaseActivity;
import com.example.android_wx.http.BaseCallBack;
import com.example.android_wx.http.HttpHelp;

public class ModifyGenderActivity extends BaseActivity {

    private AppCompatImageView backImageView;
    private AppCompatRadioButton manRadioButtom, womRadioButtom;
    private AppCompatTextView modifyTextView;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        setContentView(R.layout.activity_modify_gender);
        super.onCreate(savedInstanceState);


    }

    @Override
    public void initView() {


        backImageView = findViewById(R.id.backImageView);
        manRadioButtom = findViewById(R.id.manRadioButtom);
        womRadioButtom = findViewById(R.id.womRadioButtom);
        modifyTextView = findViewById(R.id.modifyTextView);


    }

    @Override
    public void initEvent() {

        backImageView.setOnClickListener(view -> finish());



        manRadioButtom.setOnClickListener(v -> {
            if (manRadioButtom.isChecked()) {

                womRadioButtom.setChecked(false);

            }

        });

        womRadioButtom.setOnClickListener(v -> {

            manRadioButtom.setChecked(false);

        });




        modifyTextView.setOnClickListener(view -> {
            String gender = manRadioButtom.isChecked() ? "1" : "2";
            modifyTextView.setEnabled(false);
            modifyTextView.setText("正在修改性别...");
            HttpHelp.get().ready("member", "modifyGender")
                    .add("gender", gender)
                    .get(new BaseCallBack() {
                        @Override
                        public void onSuccess(String data) {
                            App.get().getMemberData().setMemberGender(manRadioButtom.isChecked() ? 1 : 2);
                            Toast.makeText(ModifyGenderActivity.this, "修改成功", Toast.LENGTH_SHORT).show();
                            finish();
                        }

                        @Override
                        public void onFailure(String reason) {
                            Toast.makeText(ModifyGenderActivity.this, reason, Toast.LENGTH_SHORT).show();
                            modifyTextView.setEnabled(true);
                            modifyTextView.setText("修改性别");
                        }

                    });

        });

    }

}





